package com.runa.rccprotocol.dto.wukexing;

import com.runa.protocol.util.ByteUtil;
import lombok.Data;

/**
 * 2024/11/20 18:04
 * zhangYB
 */
@Data
public class WkxValveRequestData {

    public byte[] setWkxValveOpen(String serial, Integer opening, boolean ifLock) {
        byte[] requestData = new byte[17];
        int index = 0;
        requestData[index++] = 0x68;
        requestData[index++] = (byte)0x80;

        byte[] bytes = ByteUtil.hexStringToByteFlip(serial);
        for (int i = 0; i < bytes.length; i++) {
            requestData[index+i] = bytes[i];
        }
        index += 7;

        requestData[index++] = 0x04;
        requestData[index++] = 0x04;
        requestData[index++] = (byte)0xA1;
        requestData[index++] = 0x17;
        requestData[index++] = 0x01;

        requestData[index++] = (byte)(opening & 0xff);

        requestData[index++] = ByteUtil.sum(requestData, 0, index);
        requestData[index++] = 0x16;
        return requestData;
    }

    public byte[] readWkxValve(String serial) {
        byte[] requestData = new byte[16];
        int index = 0;
        requestData[index++] = 0x68;
        requestData[index++] = (byte)0x80;

        byte[] bytes = ByteUtil.hexStringToByteFlip(serial);
        for (int i = 0; i < bytes.length; i++) {
            requestData[index+i] = bytes[i];
        }
        index += 7;

        requestData[index++] = 0x01;
        requestData[index++] = 0x03;
        requestData[index++] = (byte)0x90;
        requestData[index++] = 0x1f;
        requestData[index++] = 0x01;
        requestData[index++] = ByteUtil.sum(requestData, 0, index);
        requestData[index++] = 0x16;
        return requestData;
    }


}
